﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SmartCity.ProcessEngine.ErrorCode
{
    /// <summary>
    /// 响应包装类
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class ApiResult<T>
    {
        /// <summary>
        /// 状态码
        /// </summary>
        public ApiEnum Code { get; set; }
        /// <summary>
        /// 响应消息
        /// </summary>
        public string Msg { get; set; }
        /// <summary>
        /// 响应的数据
        /// </summary>
        public T Data {  get; set; }

        /// <summary>
        /// 成功的响应
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public ApiResult<T> Success(string msg,T data) { 
            return new ApiResult<T> { Code = ApiEnum.Success, Msg = msg,Data=data };
        }

        public ApiResult<T> AddSuccess(string msg, T data)
        {
            return Success("添加" + msg + "成功", data);

        }

        public ApiResult<T> AddFail(string msg)
        {
            return Fail("添加" + msg + "失败");
        }
        /// <summary>
        /// 成功的响应
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public ApiResult<T> Fail(string msg)
        {
            return new ApiResult<T> { Code = ApiEnum.Fail, Msg = msg};
        }

        /// <summary>
        /// 错误的响应
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public ApiResult<T> Error(string msg)
        {
            return new ApiResult<T> { Code = ApiEnum.Error, Msg = msg };
        }
    }
}
